import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // 相当于组件的 data
  state: {
    count: 10,
    list: [{
      title: 'a',
      id: 1,
    },{
      title: 'b',
      id: 2,
    },{
      title: 'c',
      id: 3,
    }]
  },
  // 相当于组件的 methods
  // 修改state 必须提交 mutations
  mutations: {
    ADD_COUNT(state, payload) {
      state.count += payload
    },
    DELETE_LIST(state, id) {
      state.list = state.list.filter(item => item.id !== id)
    },
    ADD_LIST(state, payload) {
      state.list.push(payload)
    }
  },
  actions: {
  },
  modules: {
  }
})
